<?php
/**
 * 后台登录页面
 *
 * $Id:  admincp_login.php 2013-9-2  下午11:47:46 zhangzw $
 */

if(!defined('IN_FAMOUS') || !defined('IN_ADMINCP')) {
	exit('Access Denied');
}

$loginIndex = new admincp_login();
$methodName = 'action' . ucfirst($action);
if (!method_exists($loginIndex, $methodName)) {	
	showmessage('undefined_action', dreferer());
}

// 执行
$loginIndex->$methodName();

/**
 * 
 * @author zhangzw
 *
 */
class admincp_login extends famous_admincp  
{
	// 后台登录页面
	public function actionIndex(){
		
		$charset = CHARSET;
		$title = lang('admincp_login', 'login_title');
		$tips = lang('admincp_login', 'login_tips');
		$lang = lang('admincp_login');
		$sid = getglobal('sid');
		
		include template('diy:admincp/login');
	}	
	
	/**
	 * 用户后台登录
	 */
	public function actionDologin(){
		
		global $_G;
		
		$username = isset($_G['gp_username']) ? htmlspecialchars(trim($_G['gp_username'])) : '';
		$password = isset($_G['gp_password']) ? md5($_G['gp_password']) : '';
		
		$locationurl = '/admin.php?mod=login';
		if(!$username || !$password){
			showmessage('用户名密码错误', $locationurl);
		}
		
		$sql = 'SELECT * FROM '.DB::table('admin')." WHERE username='{$username}' AND password='{$password}' ";
		$admininfo = DB::fetch_first($sql);
		
		if($admininfo){
			$_SESSION['admininfo'] = array(
								'uid' 	   => $admininfo['uid'],
								'username' => $admininfo['username'],
								'groupid'  => $admininfo['groupid'],
								'logintime'=> time()		
					);			
			
			showmessage('登录成功', '/admin.php?mod=index');
		}else{
			showmessage('管理员不存在', $locationurl);
		}
	}
}


